<template>
  <page-header-wrapper>
    <applicationSearch :filterFields="['SubmitToCity']" @search="handleSearch" @reset="handleReset">
    </applicationSearch>
    <a-card :bordered="false">
      <s-table
        ref="table"
        size="default"
        :rowKey="(record, index) => index"
        :columns="columns"
        :data="loadData"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
        :scroll="{ x: true }"
      >
        <div slot="tabAction">
          <buttonSelect
            class="m-l-10"
            v-model="typeSelect"
            :options="[
              { value: '', label: '全部' },
              { value: '1', label: '已上报' },
              { value: '-1', label: '已退回' },
              { value: '2', label: '已接收' },
            ]"
            @change="handleButtonSelectChange"
          ></buttonSelect>
        </div>
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis, buttonSelect, applicationSearch } from '@/components'
import { getProposerList } from '@/api/common'
import moment from 'moment'
export default {
  name: 'cityComplexInquireList',
  components: {
    STable,
    Ellipsis,
    buttonSelect,
    applicationSearch,
  },
  computed: {
    textColor() {
      return function (text) {
        const classMap = new Map([
          ['已退回', 'text-error'],
          ['未上报', 'text-warning'],
          ['符合', 'text-success'],
          ['已接收', 'text-success'],
          ['已上报', 'text-primary'],
          ['不符合', 'text-error'],
          ['未审核', 'text-warning'],
          ['未审批', 'text-warning'],
        ])
        return classMap.get(text)
      }
    },
  },
  data() {
    return {
      typeSelect: '',
      queryParam: {
        UserID: this.$store.getters.userid,
        Mode: 'DistrictReportResult',
        strContent: {},
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 80,
          scopedSlots: { customRender: 'index' },
        },
        {
          title: '申请编号',
          align: 'center',
          dataIndex: 'ApplyNo',
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'Proposer',
        },
        {
          title: '身份证号',
          align: 'center',
          width: 176,
          dataIndex: 'IDCard',
        },
        {
          title: '区/县',
          align: 'center',
          dataIndex: 'RegionName',
          customRender: (text) => {
            return (
              <Ellipsis length={16} class={this.textColor(text)}>
                {text}
              </Ellipsis>
            )
          },
        },
        {
          title: '社区/乡镇',
          align: 'center',
          dataIndex: 'TownshipName',
          customRender: (text) => {
            return (
              <Ellipsis length={16} class={this.textColor(text)}>
                {text}
              </Ellipsis>
            )
          },
        },
        {
          title: '申请保障人数',
          align: 'center',
          dataIndex: 'CityVfyNumber',
        },
        {
          title: '社区/乡镇审核状态',
          align: 'center',
          dataIndex: 'BeviewResult',
          customRender: (text) => {
            return <span class={this.textColor(text)}>{text}</span>
          },
        },
        {
          title: '区级审核',
          align: 'center',
          dataIndex: 'VerifyResult',
          customRender: (text) => {
            return <span class={this.textColor(text)}>{text}</span>
          },
        },
        {
          title: '审核日期',
          align: 'center',
          dataIndex: 'VerifyDate',
          customRender: (text) => (text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '/'),
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'SubmitToCity',
          customRender: (value) => {
            const textMap = new Map([
              ['0', '未上报'],
              ['1', '已上报'],
              ['2', '已接收'],
              ['-1', '已退回'],
            ])
            const text = textMap.get(value)
            return <span class={this.textColor(text)}>{text}</span>
          },
        },
        {
          title: '市(级)审批',
          align: 'center',
          dataIndex: 'CityVfyResult',
          customRender: (text) => {
            let value = '未审批'
            if (!this.$isEmpty(text)) {
              value = text
            }
            return <span class={this.textColor(value)}>{value}</span>
          },
        },
        {
          title: '上报人',
          align: 'center',
          dataIndex: 'SubmitToUser',
          customRender: (text) => text || '/',
        },
        {
          title: '上报时间',
          align: 'center',
          dataIndex: 'SubmitToDate',
          customRender: (text) => (text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '/'),
        },
        {
          title: '接收人',
          align: 'center',
          dataIndex: 'ProcessUser',
          customRender: (text) => text || '/',
        },
        {
          title: '接收时间',
          align: 'center',
          dataIndex: 'ProcessDate',
          customRender: (text) => (text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '/'),
        },
        {
          title: '处理信息',
          align: 'center',
          dataIndex: 'ProcessInfo',
          customRender: (text) => {
            return <Ellipsis length={16}>{text || '/'}</Ellipsis>
          },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        requestParameters.strContent.SubmitToCity = this.typeSelect
        return getProposerList(requestParameters).then((res) => {
          return res
        })
      },
    }
  },
  methods: {
    handleSearch(values) {
      this.queryParam.strContent = values
      this.$refs.table.refresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.typeSelect = ''
      this.$refs.table.refresh(true)
    },
    handleButtonSelectChange(e) {
      this.$refs.table.refresh(true)
    },
  },
}
</script>
<style lang="less" scoped>
/deep/ .ant-table {
  td,
  th {
    white-space: nowrap;
  }
}
</style>
